//
//  RCTrainOrderDetailInfoDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-11-29.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCTrainOrderDetailInfoDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSString+NSString_Ex_.h"
#import "NSArray+EX.h"
#import "RCTranlistDataModel.h"

@implementation RCTicketOrderUserInfo

-(void)dealloc{
    self.userName = nil;
    self.userNumType = nil;
    self.userNum = nil;
    [super dealloc];
}

@end

@implementation RCTrainOrderDetailInfoItem

@synthesize ticketName = _ticketName;
@synthesize ticketPrice = _ticketPrice;
@synthesize ticketStatus = _ticketStatus;

-(id)init{
    self = [super init];
    if (self) {
        _ticketName = nil;
        _ticketPrice = nil;
        _ticketStatus = NO;
    }
    return self;
}

-(void)dealloc{
    self.ticketName = nil;
    self.ticketPrice = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCTrainOrderDetailInfoItem *retObject = nil;
    retObject = [[RCTrainOrderDetailInfoItem alloc]init];
    retObject.ticketName = [data stringValueForKey:@"ticketname" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.ticketPrice = [data stringValueForKey:@"ticketprice" defaultValue:nil operation:NSStringOperationTypeTrim];
    NSString *status = [data stringValueForKey:@"ticketstatus" defaultValue:nil operation:NSStringOperationTypeTrim];
    if ([NSString stringIsNullOrEmpty:status]) {
        retObject.ticketStatus = YES;
    }else{
        retObject.ticketStatus = NO;
    }
    
    return [retObject autorelease];
}

@end

@implementation RCTrainOrderDetailInfoDataModel

@synthesize ticketItemArray = _ticketItemArray;

-(id)init{
    self = [super init];
    if (self) {
        _ticketItemArray = nil;
    }
    
    return self;
}

-(void)dealloc{
    self.ticketItemArray = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    
    NSDictionary *dict = [data dictionaryValueForKey:@"data" defaultValue:nil];
    if (nil == dict) {
        return nil;
    }
    
    NSArray *dictItemArray = [dict arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dictItemArray && 0 == [dictItemArray count]) {
        return nil;
    }
    
    RCTrainOrderDetailInfoDataModel *retObject = nil;
    retObject = [[RCTrainOrderDetailInfoDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    
    NSMutableArray *itemTempArray = [[NSMutableArray alloc]init];
    
    for (int i = 0; i < [dictItemArray count]; i++) {
        NSDictionary *dictItem = [dictItemArray safeObjectAtIndex:i];
        if (nil == dictItem) {
            continue;
        }
        
        RCTrainOrderDetailInfoItem *item = [RCTrainOrderDetailInfoItem parseDataFromJSON:dictItem];
        if (nil == item) {
            continue;
        }
        
        [itemTempArray addObject:item];
        
    }
    retObject.ticketItemArray = [NSArray arrayWithArray:itemTempArray];
    [itemTempArray release];
    
    return [retObject autorelease];
    
}

@end

@implementation RCFlyOrderDetailInfoItem

@synthesize flyType = _flyType;
@synthesize price = _price;
@synthesize discount = _discount;
@synthesize originPrice = _originPrice;

-(id)init{
    self = [super init];
    if (self) {
        _flyType = nil;
        _price = 0;
        _discount = 0;
        _originPrice = 0;
    }
    
    return self;
}

-(void)dealloc{
    self.flyType = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    
    RCFlyOrderDetailInfoItem *retObject = nil;
    retObject = [[RCFlyOrderDetailInfoItem alloc]init];
    if (nil == retObject) {
        return nil;
    }
    
    retObject.flyType = [data stringValueForKey:@"cabintypename_go" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.price = [data floatValueForKey:@"price_go" defaultValue:0];
    CGFloat discount = [data floatValueForKey:@"discount_go" defaultValue:0];
    retObject.discount = discount/10;
    if (retObject.discount != 0) {
        retObject.originPrice = retObject.price/retObject.discount;
    }
    
    return [retObject autorelease];
}

@end

@implementation RCFlyOrderDetailInfoDataModel

@synthesize flyItemArray = _flyItemArray;

-(id)init{
    self = [super init];
    if (self) {
        _flyItemArray = nil;
    }
    
    return self;
}

-(void)dealloc{
    self.flyItemArray = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    
    NSDictionary *dict = [data dictionaryValueForKey:@"data" defaultValue:nil];
    if (nil == dict) {
        return nil;
    }
    
    NSArray *dictItemArray = [dict arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dictItemArray && 0 == [dictItemArray count]) {
        return nil;
    }
    
    RCFlyOrderDetailInfoDataModel *retObject = nil;
    retObject = [[RCFlyOrderDetailInfoDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    
    NSMutableArray *itemTempArray = [[NSMutableArray alloc]init];
    
    for (int i = 0; i < [dictItemArray count]; i++) {
        NSDictionary *dictItem = [dictItemArray safeObjectAtIndex:i];
        if (nil == dictItem) {
            continue;
        }
        
        RCFlyOrderDetailInfoItem *item = [RCFlyOrderDetailInfoItem parseDataFromJSON:dictItem];
        if (nil == item) {
            continue;
        }
        
        [itemTempArray addObject:item];
        
    }
    retObject.flyItemArray = [NSArray arrayWithArray:itemTempArray];
    [itemTempArray release];
    
    return [retObject autorelease];
    
}

@end

@implementation RCFlyOrderItemInfo

@synthesize startDate = _startDate;
@synthesize startTime = _startTime;
@synthesize endTime = _endTime;
@synthesize startCity = _startCity;
@synthesize endCity = _endCity;
@synthesize startAirport = _startAirport;
@synthesize endAirport = _endAirport;
@synthesize airCompany = _airCompany;
@synthesize airName = _airName;
@synthesize airTypeName = _airTypeName;
@synthesize flyType = _flyType;
@synthesize price = _price;
@synthesize originPrice = _originPrice;
@synthesize airportFee = _airportFee;
@synthesize fuelFee = _fuelFee;
@synthesize startCityCode = _startCityCode;
@synthesize endCityCode = _endCityCode;


-(void)dealloc{
    self.startDate = nil;
    self.startTime = nil;
    self.endTime = nil;
    self.startCity = nil;
    self.endCity = nil;
    self.startAirport = nil;
    self.endAirport = nil;
    self.airCompany = nil;
    self.airName = nil;
    self.airTypeName = nil;
    self.price = nil;
    self.originPrice = nil;
    self.airportFee = nil;
    self.fuelFee = nil;
    self.flyType = nil;
    self.startCityCode = nil;
    self.endCityCode = nil;
    [super dealloc];
}

-(void)initFlyOrderItemWithPlaneItem:(RCPlaneItemDataModel *)planeItem{
    if (nil == planeItem) {
        return;
    }
    self.airportFee = planeItem.airportFee;
    self.fuelFee = planeItem.fuelFee;
    self.price = planeItem.price;
    
    NSString *time = planeItem.time;
    if (![NSString stringIsNullOrEmpty:time]) {
        NSArray *timeArray = [time componentsSeparatedByString:@"—"];
        if (timeArray != nil && [timeArray count] >0) {
            NSString *starTime = [timeArray safeObjectAtIndex:0];
            self.startTime = [starTime trim];
        }
        
        if (timeArray != nil && [timeArray count] >1) {
            NSString *endTime = [timeArray safeObjectAtIndex:1];
            self.endTime = [endTime trim];
        }
    }
    
    NSString *airName = planeItem.airportName;
    if (![NSString stringIsNullOrEmpty:airName]) {
        NSArray *airNameArray = [airName componentsSeparatedByString:@"—"];
        if (airNameArray != nil && [airNameArray count] >0) {
            NSString *starAirName = [airNameArray safeObjectAtIndex:0];
            self.startAirport = [starAirName trim];
        }
        
        if (airNameArray != nil && [airNameArray count] >1) {
            NSString *endAirName = [airNameArray safeObjectAtIndex:1];
            self.endAirport = [endAirName trim];
        }
    }
    
    NSString *planeInfo = planeItem.planeinfo;
    if (![NSString stringIsNullOrEmpty:planeInfo]) {
        NSArray *planeInfoArray = [planeInfo componentsSeparatedByString:@" "];
        if (planeInfoArray != nil && [planeInfoArray count] >0) {
            NSString *company = [planeInfoArray safeObjectAtIndex:0];
            self.airCompany = [company trim];
        }
        
        if (planeInfoArray != nil && [planeInfoArray count] >1) {
            NSString *airName = [planeInfoArray safeObjectAtIndex:1];
            self.airName = [airName trim];
        }
        
        if (planeInfoArray != nil && [planeInfoArray count] >2) {
            NSString *airType = [planeInfoArray safeObjectAtIndex:2];
            self.airTypeName = [airType trim];
        }
    }
}

@end
